package com.ts.api.module.api.convert.market.adapter;

import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.ts.api.module.api.convert.core.annotation.ApiConsumerMarket;
import com.ts.api.module.api.convert.core.annotation.ApiConsumerMarketConvertType;
import com.ts.api.module.api.convert.core.entity.ApiApplyParameter;
import com.ts.api.module.api.convert.core.entity.ApiDataExchangeParameter;
import com.ts.api.module.api.convert.core.utils.ApiEncryptUtils;
import com.ts.api.module.api.convert.market.handler.ConsumerMarketConvertHandler;

import java.util.Map;

/**
 *  下游贷超撞库-ip
 *
 *  @author Pan
 */
@ApiConsumerMarket(marketId = "consumerMarketIpAdapter", type = ApiConsumerMarketConvertType.DATA_EXCHANGE_IP)
public class ConsumerMarketIpAdapter implements ConsumerMarketConvertHandler {

    private static final String KEY = "8cf70e3cf21ab7c1bca151943e6b2df80ba6a8d9b217940ac6c6b53ca8d6ea5e";

    @Override
    public Object dataExchange(ApiDataExchangeParameter apiDataExchangeParameter) throws Exception {
        Map<String, String> reqMap = ApiEncryptUtils.encryptData(KEY, apiDataExchangeParameter);
        return reqMap;
    }

    @Override
    public boolean hasDataExchangeSuc(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return false;
        }
        return Eq.object(jsonObject.getInteger("code"), 1000);
    }

    @Override
    public Object federate(ApiApplyParameter apiApplyParameter) throws Exception {
       return null;
    }

    @Override
    public boolean hasSucFederate(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return false;
        }
        return Eq.object(jsonObject.getInteger("code"), 1000);
    }
}
